

TARGET = tftpd

CC = g++
CFLAGS = -g -std=c++11  -c -I .
LD  = -lpthread
HD  =
OBJECT_DIR = ./obj
DIRS := $(shell find $(SOURCE_DIR) $(PROJECT_DIR) -maxdepth 3 -type d)
SOURCES = $(foreach dir,$(DIRS),$(wildcard $(dir)/*.cpp))
OBJ_FILES = $(notdir $(patsubst %.cpp, %.o, $(SOURCES)))


TARGET:PRE COMPILE LINK 

COMPILE:$(OBJ_FILES)
$(OBJ_FILES):%.o:%.cpp
	@echo compiling  $(<F)...
	@$(CC) -c $< -o $(OBJECT_DIR)/$@ $(HD) $(CFLAGS) $(INCLUDE) -fPIC

LINK:$(OBJ_FILES)
	@$(CC) -o tftpd $(OBJECT_DIR)/tftpd.o $(OBJECT_DIR)/log.o $(OBJECT_DIR)/tftpserver.o $(LD)

.PHONY:clean

clean:
	rm -f $(OBJECT_DIR)/*.o
	rm -f tftpd
	rm -f tftp
	rm -f *.o

.PHONY:PRE
PRE:
ifneq  ($(OBJECT_DIR), $(wildcard $(OBJECT_DIR)))
	@mkdir -p $(OBJECT_DIR)
endif
.PHONY:build
build:TARGET
